<?php
/**
 * Manage categories  list for filter
 *
 * @package    letsManager
 * @subpackage form
 * @author     Jerome Fouilloy
 * @version    SVN: $Rev$
 */
class LetsCategoryFilterForm extends BaseForm
{
  public function setup()
  {
    parent::setup();
    $user = sfContext::getInstance()->getUser();
    $this->setDefault('category_id',$this->getOption('category_id'));
    $query = LetsMainCategoryTable::getQueryForUser($user,$user->hasCredential(LetsManagerRights::USE_PRIVATE_CATEGORY));
    $this->setWidgets(array(
      'category_id' => new sfWidgetFormDoctrineChoice(array(
      'model' => 'LetsMainCategory',
      'query' => $query,
      'add_empty' => '- Toutes les catégories -'
      )),
      'query' => new sfWidgetFormInputText()
    ));
    $this->setValidators(array(
      'category_id'=> new sfValidatorDoctrineChoice(array(
        'model' => 'LetsMainCategory',
        'query' => $query
      )),
      'query' => new sfValidatorString(array('min_length'=>2),array('min_length'=>'Saisir au moins 2 lettres')),
    ));

//$this->widgetSchema['category_id']->setOption('query', LetsSubCategoryTable::getInstance()->getQueryForUser($user));
    $this->widgetSchema->setLabels(array(
      'category_id' => 'Catégorie',
      'query' => 'Mot clef',
    ));
  }
}

?>